<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .grey {
            color: grey;
        }

        .black {
            color: black;
        }
    </style>
</head>

<body>
    <input type="text" value="请输入搜索关键字" class="grey" id="txt">
    <script>
        var txt = document.getElementById("txt");
        txt.onfocus = function () {
            if (txt.value === "请输入搜索关键字") {
                txt.value = "";
                txt.className = "black";
            }
        };
        txt.onblur = function () {
            if (txt.value === "") {
                txt.value = "请输入搜索关键字";
                txt.className = "grey";
            }
        };
    </script>
</body>

</html>